<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>lorismorph</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="lorisread.html" title="lorisread" />
    <link rel="next" href="lorisplay.html" title="lorisplay" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">lorismorph</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="lorisread.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="lorisplay.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="lorismorph"></a>
      <div class="titlepage"></div>
      <a id="IndexLorisMorph" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">lorismorph</span>
        </h2>
        <p>lorismorph — Morphs two stored sets of bandwidth-enhanced partials
    and stores a new set of partials representing the morphed
    sound. The morph is performed by linearly interpolating the
    parameter envelopes (frequency, amplitude, and bandwidth, or
    noisiness) of the bandwidth-enhanced partials according to
    control-rate frequency, amplitude, and bandwidth morphing
    functions.    </p>
      </div>
      <div class="refsect1">
        <a id="idp120483056"></a>
        <h2>Syntax</h2>
        <pre class="synopsis"><span class="command"><strong>lorismorph</strong></span> isrcidx, itgtidx, istoreidx, kfreqmorphenv, kampmorphenv, kbwmorphenv</pre>
      </div>
      <div class="refsect1">
        <a id="idp120549776"></a>
        <h2>Description</h2>
        <p><span class="emphasis"><em>lorismorph</em></span> morphs two stored sets of bandwidth-enhanced
    partials and stores a new set of partials representing the morphed
    sound. The morph is performed by linearly interpolating the
    parameter envelopes (frequency, amplitude, and bandwidth, or
    noisiness) of the bandwidth-enhanced partials according to
    control-rate frequency, amplitude, and bandwidth morphing
    functions.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp120551584"></a>
        <h2>Initialization</h2>
        <p><span class="emphasis"><em>istoreidx, ireadidx, isrcidx, itgtidx</em></span> are
    labels that identify a stored set of bandwidth-enhanced
    partials. <span class="emphasis"><em>lorisread</em></span> imports partials from a SDIF file and stores them
    with the integer label istoreidx. <span class="emphasis"><em>lorismorph</em></span> morphs sets of partials
    labeled <span class="emphasis"><em>isrcidx</em></span> and <span class="emphasis"><em>itgtidx</em></span>, and stores the resulting partials with
    the integer label <span class="emphasis"><em>istoreidx</em></span>. <span class="emphasis"><em>lorisplay</em></span> renders the partials stored
    with the label <span class="emphasis"><em>ireadidx</em></span>. The labels are used only at initialization
    time, and may be reused without any cost or benefit in efficiency, and
    without introducing any interaction between instruments or
    instances.</p>
      </div>
      <div class="refsect1">
        <a id="idp120556544"></a>
        <h2>Performance</h2>
        <p><span class="emphasis"><em>lorismorph</em></span> generates a set of bandwidth-enhanced partials by
    morphing two stored sets of partials, the source and target partials,
    which may have been imported using <span class="emphasis"><em>lorisread</em></span>, or generated by another
    unit generator, including another instance of <span class="emphasis"><em>lorismorph</em></span>. The morph is
    performed by interpolating the parameters of corresponding (labeled)
    partials in the two source sounds. The sound morph is
    described by three control-rate morphing envelopes. <span class="emphasis"><em>kfreqmorphenv</em></span>
    describes the interpolation of partial frequency values in the two
    source sounds. When <span class="emphasis"><em>kfreqmorphenv</em></span> is 0, partial frequencies are
    obtained from the partials stored at <span class="emphasis"><em>isrcidx</em></span>. When <span class="emphasis"><em>kfreqmorphenv</em></span> is 1,
    partial frequencies are obtained from the partials at <span class="emphasis"><em>itgtidx</em></span>. When
    <span class="emphasis"><em>kfreqmorphenv</em></span> is between 0 and 1, the partial frequencies are
    interpolated between corresponding source and target
    partials. Interpolation of partial amplitudes and bandwidth
    (noisiness) coefficients are similarly described by <span class="emphasis"><em>kampmorphenv</em></span> and
    <span class="emphasis"><em>kbwmorphenv</em></span>.</p>
      </div>
      <div class="refsect1">
        <a id="idp120563296"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the lorismorph opcode. It uses the file <a class="ulink" href="examples/lorismorph.csd" target="_top"><em class="citetitle">lorismorph.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp120565152"></a>
          <p class="title">
            <strong>Example 442. Example of the lorismorph opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac      <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o lorismorph.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1
<span class="comment">; clarinet.sdif and meow.sdif can be found in /manual/examples</span>

<span class="comment">; Morph the partials in meow.sdif into the partials in clarinet.sdif over the duration of</span>
<span class="comment">; the sustained portion of the two tones (from .2 to 2.0 seconds in the meow, and from</span>
<span class="comment">; .5 to 2.1 seconds in the clarinet). The onset and decay portions in the morphed sound are</span>
<span class="comment">; specified by parameters p4 and p5, respectively. The morphing time is the time between the</span>
<span class="comment">; onset and the decay. The meow partials are shfited in pitch to match the pitch of the clarinet</span>
<span class="comment">; tone (D above middle C). </span>

<span class="oblock">instr</span> 1

ionset	<span class="op">=</span> p4
idecay	<span class="op">=</span> p5
itmorph <span class="op">=</span> p3 <span class="op">-</span> (ionset <span class="op">+</span> idecay)
ipshift	<span class="op">=</span> <span class="opc">cpspch</span>(8.02)<span class="op">/</span><span class="opc">cpspch</span>(8.08)
    
ktme	<span class="opc">linseg</span>	0, ionset, .2, itmorph, 2.0, idecay, 2.1    <span class="comment">; meow time function, morph from .2 to 2.0 seconds</span>
ktcl	<span class="opc">linseg</span>	0, ionset, .5, itmorph, 2.1, idecay, 2.3    <span class="comment">; clarinet time function, morph from .5 to 2.1 seconds</span>
kmurph	<span class="opc">linseg</span>	0, ionset, 0, itmorph, 1, idecay, 1
	lorisread  ktme, "meow.sdif", 1, ipshift, 2, 1, .001
	lorisread  ktcl, "clarinet.sdif", 2, 1, 1, 1, .001
	lorismorph 1, 2, 3, kmurph, kmurph, kmurph
asig	lorisplay  3, 1, 1, 1
	<span class="opc">outs</span>	   asig, asig
<span class="oblock">endin</span>

<span class="comment">; Morph the partials in clarinet.sdif into the partials in meow.sdif. The start and end times</span>
<span class="comment">; for the morph are specified by parameters p4 and p5, respectively. The morph occurs over the</span>
<span class="comment">; second of four pitches in each of the sounds, from .75 to 1.2 seconds in the flutter-tongued</span>
<span class="comment">; clarinet tone, and from 1.7 to 2.2 seconds in the cat's meow. Different morphing functions are</span>
<span class="comment">; used for the frequency and amplitude envelopes, so that the partial amplitudes make a faster  </span>
<span class="comment">; transition from clarinet to cat than the frequencies. (The bandwidth envelopes use the same          </span>
<span class="comment">; morphing function as the amplitudes.) </span>

<span class="oblock">instr</span> 2

ionset	 <span class="op">=</span> p4
imorph	 <span class="op">=</span> p5 <span class="op">-</span> p4
irelease <span class="op">=</span> p3 <span class="op">-</span> p5
    
ktclar	<span class="opc">linseg</span>	0, ionset, .75, imorph, 1.2, irelease, 2.4
ktmeow	<span class="opc">linseg</span>	0, ionset, 1.7, imorph, 2.2, irelease, 3.4
    
kmfreq	<span class="opc">linseg</span>	0, ionset, 0, .75<span class="op">*</span>imorph, .25, .25<span class="op">*</span>imorph, 1, irelease, 1
kmamp	<span class="opc">linseg</span>	0, ionset, 0, .75<span class="op">*</span>imorph, .9, .25<span class="op">*</span>imorph, 1, irelease, 1
    
	lorisread  ktclar, "clarinet.sdif", 1, 1, 1, 1, .001
	lorisread  ktmeow, "meow.sdif", 2, 1, 1, 1, .001
	lorismorph 1, 2, 3, kmfreq, kmamp, kmamp
asig	lorisplay  3, 1, 1, 1
	<span class="opc">outs</span>	   asig, asig
<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="comment">;     strt   dur   onset   decay</span>
<span class="stamnt">i</span> 1    0      3     .25     .15
<span class="stamnt">i</span> 1    +      1     .10     .10
<span class="stamnt">i</span> 1    +      6    1.      1.

<span class="comment">;    strt   dur  morph_start   morph_end</span>
 <span class="stamnt">i</span> 2    9    4     .75           2.75

<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp120569440"></a>
        <h2>Credits</h2>
        <p>This implementation of the Loris unit generators was written by Kelly
    Fitz (<a class="ulink" href="mailto:loris@cerlsoundgroup.org" target="_top">loris@cerlsoundgroup.org</a>). It is patterned after a prototype implementation of the
    <span class="emphasis"><em>lorisplay</em></span> unit generator written by Corbin Champion, and based on the
    method of Bandwidth-Enhanced Additive Synthesis and on the sound
    morphing algorithms implemented in the Loris library for sound
    modeling and manipulation. The opcodes were further adapted as a
    plugin for Csound 5 by Michael gogins.</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="lorisread.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="lorisplay.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">lorisread </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> lorisplay</td>
        </tr>
      </table>
    </div>
  </body>
</html>
